package com.hdu.controller.contentManagement;

import com.hdu.entity.TeachPlan;
import com.hdu.pojo.Result;
import com.hdu.service.ITeachPlanService;
import com.hdu.vo.BindTeachPlanMediaVo;
import com.hdu.vo.TeachPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/teachPlan")
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
public class TeachPlanController {

    private final ITeachPlanService teachPlanService;

    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/{courseId}/tree-nodes")
    public Result<List<TeachPlanVo>> getTreeNodes(@PathVariable Long courseId) {
        return Result.success(teachPlanService.findTeachPlanTree(courseId));
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping
    public Result<?> saveTeachPlan(@RequestBody TeachPlan teachPlan) {
        teachPlanService.saveTeachPlan(teachPlan);
        return Result.success();
    }

    @ApiOperation("课程计划删除")
    @DeleteMapping("/{teachPlanId}")
    public void deleteTeachPlan(@PathVariable Long teachPlanId) {
        teachPlanService.deleteTeachPlan(teachPlanId);
    }

    @ApiOperation("课程计划排序")
    @PostMapping("/{moveType}/{teachPlanId}")
    public void orderByTeachPlan(@PathVariable String moveType, @PathVariable Long teachPlanId) {
        teachPlanService.orderByTeachPlan(moveType, teachPlanId);
    }

    @ApiOperation("课程计划与媒资信息绑定")
    @PostMapping("/association/media")
    public void associationMedia(@RequestBody BindTeachPlanMediaVo bindTeachPlanMediaVo) {
        teachPlanService.associationMedia(bindTeachPlanMediaVo);
    }

    @ApiOperation("课程计划解除媒资信息绑定")
    @DeleteMapping("/association/media/{teachPlanId}/{mediaId}")
    public void unAssociationMedia(@PathVariable Long teachPlanId, @PathVariable String mediaId) {
        teachPlanService.unAssociationMedia(teachPlanId, mediaId);
    }

    @ApiOperation("课程计划查询")
    @PostMapping("/{teachPlanId}")
    public Result<TeachPlan> getTeachPlan(@PathVariable Long teachPlanId) {
        return Result.success(teachPlanService.getTeachPlan(teachPlanId));
    }
}
